randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
people <- c(
"Jack Williams",
"Jessica Blois",
"Eric Grimm",
"Alison Smith",
"Simon Goring",
"Allan Ashworth",
"Timshel Purdum",
"Phil Buckland",
"Don Charles",
"Thomas Giesecke",
"Claudio Latorre",
"Hikaru Takahara"
)
terms <- rep(c(1,2,3,4), 3)
randTerms <- sample(terms, 12, replace=F)
cbind(people, randTerms)
citation()
dat <- c(2,3,7,8,9,6,12, 17, 22, 23, 37, 38, 102, 103, 107)
hist(dat)
hist(dat, breaks=10)
hist(dat, breaks=20)
density(dat)
plot.density(dat)
plot(density(dat))
?quantile
quantile(dat, probs=seq(0,1,.05))
quantile(dat, probs=seq(0,1,.025))
quantile(dat, probs=.05
)
hist(dat)
hist(dat, breaks=20)
hist(log(dat), breaks=20)
sqrt
?swrt
?sqrt
hist(sqrt(dat))
hist(sqrt(dat), breaks=10)
hist(sqrt(dat), breaks=20)
?var
hist(1/var(data), breaks=15)
hist(1/var(data))
var(data)
hist(1/var(dat), breaks=15)
hist(1/var(dat))
1/var(dat)
dat
hist(1/dat)
hist(1/dat, breaks=20)
quantiles(1/dat, prob=0.05)
quantile(1/dat, prob=0.05)
1/0.009599855
mean(dat)
sd(dat)
?pnorm
pnorm(dat, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(mean=mean(dat), sd=sd(dat), lower.tail=T)
plot(function(x) dnorm(x, log = TRUE), -60, 50,
main = "log { Normal density }")
function(x) pnorm(x, log.p = TRUE), -50, 10,
main = "log { Normal Cumulative }")
plot(function(x) pnorm(x, log.p = TRUE), -50, 10,
main = "log { Normal Cumulative }")
curve(log(pnorm(x)), add = TRUE, col = "red", lwd = 2)
pnorm(quantile(dat, probs=seq(0,1,.025)), mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(qdat, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(dat, mean=mean(dat), sd=sd(dat), lower.tail=T)
100/15
pnorm(.05, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(.95, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(5, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(95, mean=mean(dat), sd=sd(dat), lower.tail=T)
pnorm(5, mean=mean(dat), sd=sd(dat), lower.tail=T) * mean(dat)
hist(dat)
hist(dat, breaks=20)
pnorm(2, mean=mean(dat), sd=sd(dat), lower.tail=T)
qnorm(1-.025)
pnorm(2, mean=mean(dat), sd=sd(dat), lower.tail=T)
qnorm(2, mean=mean(dat), sd=sd(dat), lower.tail=T)
qnorm(2, mean=mean(dat), sd=sd(dat), lower.tail=F)
quantiles(dat)
quantile(dat)
quantile(dat, seq=0,100, 10)
quantile(dat, seq(0,100, 10))
quantile(dat, seq(0,1, .10))
quantile(dat, seq(0,1, .05))
pnorm(7.5, mean = mean(dat), sd = sd(dat))
pnorm(7.5, mean = mean(dat), sd = sd(dat), lower.tail=F)
pnorm(7.5, mean = mean(dat), sd = sd(dat), lower.tail=T)
pnorm(2.5, mean = mean(dat), sd = sd(dat), lower.tail=T)
pnorm(2.7, mean = mean(dat), sd = sd(dat), lower.tail=T)
pnorm(22.4, mean = mean(dat), sd = sd(dat), lower.tail=T)
pnorm(22.4, mean = mean(dat), sd = sd(dat), lower.tail=F)
quantile(dat, probs=.05)
Test1 <- 2
Test2 <- 7
Test1 <= quantile(dat, probs=.05)
Test2 <= quantile(dat, probs=.05)
qnorm(.05, mean = mean(dat), sd = sd(dat))
qnorm(5, mean = mean(dat), sd = sd(dat))
qnorm(5, mean = mean(dat), sd = sd(dat), lower.tail=T)
dnorm(5, mean = mean(dat), sd = sd(dat), lower.tail=T)
dnorm(5, mean = mean(dat), sd = sd(dat))
dnorm(.05, mean = mean(dat), sd = sd(dat))
pnorm(.05, mean = mean(dat), sd = sd(dat))
pnorm(.1, mean = mean(dat), sd = sd(dat))
pnorm(.2, mean = mean(dat), sd = sd(dat))
pnorm(5, mean = mean(dat), sd = sd(dat))
pnorm(50, mean = mean(dat), sd = sd(dat))
3+6
x <- 3*4
objectname <- value
# objectname <- value
i_use_snake_case <- 34
othersUseCamelCase <- 22
this_is_a_very_long_name <- 5
this_is_a_very_long_name
'2d' <- 2
2d
'2d'
get('2d')
weight_kg <- 55
weight_kg
weight_kg *2.2
weight_lbs <- weight_kg *2.2
weight_kg <- 57.5
weight_lbs <- weight_kg *2.2
weight_lbs
rm(weight_lbs)
weight_lb <- weight_kg *2.2
weight_kg <- 60
weight_lb
# function_name(argument1 = myfirstargument, argument2 = mysecondargument, ...)
seq(1,10)
?seq
seq(0, 1, length.out = 11)
seq(0, 1, length.out = 20)
seq(0, 1, by=2)
seq(0, 1, 2)
seq(0, 9, 2)
seq(0, 9, 2, 6)
class(x)
??install
?date
objects()
ls()
rm(x)
getwd(_)
getwd()
?atan2
atan2(y=100, x=100)*180/pi
atan2(y=-100, x=100)*180/pi
atan2(y=-100, x=-100)*180/pi
atan2(y=100, x=-100)*180/pi
atan2(y=0, x=100)*180/pi
atan2(y=0, x=-100)*180/pi
atan2(y=0, x=-100)
atan2(y=100, x=0)
atan2(y=100, x=0)*(180/pi)
library('vegan')
#uncomment the following line if you haven't installed these packages yet
#install.packages(c('vegan', 'cluster', 'rioja', 'gplots', 'adjclust))
library('vegan')
library('cluster')
library('rioja')
library('gplots')
library('adjclust')
# also uses stats package, included with base R.
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
pollen12K <- read.csv(file="data/12000.interp.data_clean_sites.csv")
scpdSM_euc <- vegdist(scpdSM, method="euclidean")
scpdSM_bray <- vegdist(scpdSM, method="bray")
scpdSM_chao <- vegdist(scpdSM, method="chao")
print(scpdSM_euc)
print(scpdSM_bray)
print(scpdSM_chao)
clust_euc_ward.D2 <- hclust(scpdSM_euc, method="ward.D2")
clust_euc_neighbor <- hclust(scpdSM_euc, method="single")
clust_euc_upgma <- hclust(scpdSM_euc, method="average") #UPGMA
clust_euc_wpgma <- hclust(scpdSM_euc, method="mcquitty") #WPGMA
clust_bray_ward.D2 <- hclust(scpdSM_bray, method="ward.D2")
clust_bray_neighbor <- hclust(scpdSM_bray, method="single")
clust_bray_upgma <- hclust(scpdSM_bray, method="average") #UPGMA
clust_bray_wpgma <- hclust(scpdSM_bray, method="mcquitty") #WPGMA
clust_chao_ward.D2 <- hclust(scpdSM_chao, method="ward.D2")
clust_chao_neighbor <- hclust(scpdSM_chao, method="single")
clust_chao_upgma <- hclust(scpdSM_chao, method="average") #UPGMA
clust_chao_wpgma <- hclust(scpdSM_chao, method="mcquitty") #WPGMA
plotting_objs <- ls()[grep("clust", ls())]
# Note: I'm writing the cluster diagram to a pdf file, so it's easier to read. You can uncomment the pdf() and dev.off() lines to print to the screen, or just not copy those lines
pdf(file="output/cluster_diagrams.pdf", height=11, width=8.5)
par(mfcol=c(4,3), mar=c(2,4,1,1)+.01)
for (i in 1:length(plotting_objs)){
plot(get(plotting_objs[i]), cex=0.75, xlab=NA, sub=NA, main=plotting_objs[i], hang=-.1)
}
dev.off()
dissimColors <- gray.colors(30, start = 0.9, end = 0.1, gamma = 2.2, alpha = NULL)
ages <- as.numeric(rownames(scpdSM))
ageColors <- rainbow(length(ages), start=0, end=4/6)
heatmap(scpdSM, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors, tracecol=NA)
constrained <- chclust(scpdSM_bray, method="coniss")
bstick <- bstick(constrained, 10)
ngroups <- min(which(bstick$dispersion>bstick$bstick))
x <- strat.plot(scpdSM, yvar=ages, title="", y.rev=T, cex.xlabel=0.5,cex.yaxis=0.5, cex.axis=0.5, clust=constrained)
addClustZone(x, constrained, col="red", ngroups)
fit1 <- adjClust(scpdSM_bray, type="dissimilarity")
plot(fit1, leaflab="perpendicular")
fit1
?adjClust
constrained
?chclust
?heatmap
as.dendrogram(constrained)
plot(as.dendrogram(constrained))
plot(as.dendrogram(fit1))
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="ward.D2"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA, Rowv=FALSE)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA, Colv=FALSE)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) rioja::chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
consDendro <- as.dendrogram(constrained)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) rioja::chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, Rowv= -consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) rioja::chclust(m, method="coniss"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA, dendrogram="row")
consDendro
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
pollen12K <- read.csv(file="data/12000.interp.data_clean_sites.csv")
scpdSM_euc <- vegdist(scpdSM, method="euclidean")
scpdSM_bray <- vegdist(scpdSM, method="bray")
scpdSM_chao <- vegdist(scpdSM, method="chao")
# print(scpdSM_euc)
# print(scpdSM_bray)
# print(scpdSM_chao)
clust_euc_ward.D2 <- hclust(scpdSM_euc, method="ward.D2")
clust_euc_neighbor <- hclust(scpdSM_euc, method="single")
clust_euc_upgma <- hclust(scpdSM_euc, method="average") #UPGMA
clust_euc_wpgma <- hclust(scpdSM_euc, method="mcquitty") #WPGMA
clust_bray_ward.D2 <- hclust(scpdSM_bray, method="ward.D2")
clust_bray_neighbor <- hclust(scpdSM_bray, method="single")
clust_bray_upgma <- hclust(scpdSM_bray, method="average") #UPGMA
clust_bray_wpgma <- hclust(scpdSM_bray, method="mcquitty") #WPGMA
clust_chao_ward.D2 <- hclust(scpdSM_chao, method="ward.D2")
clust_chao_neighbor <- hclust(scpdSM_chao, method="single")
clust_chao_upgma <- hclust(scpdSM_chao, method="average") #UPGMA
clust_chao_wpgma <- hclust(scpdSM_chao, method="mcquitty") #WPGMA
plotting_objs <- ls()[grep("clust", ls())]
# Note: I'm writing the cluster diagram to a pdf file, so it's easier to read. You can uncomment the pdf() and dev.off() lines to print to the screen, or just not copy those lines
pdf(file="output/cluster_diagrams.pdf", height=11, width=8.5)
par(mfcol=c(4,3), mar=c(2,4,1,1)+.01)
for (i in 1:length(plotting_objs)){
plot(get(plotting_objs[i]), cex=0.75, xlab=NA, sub=NA, main=plotting_objs[i], hang=-.1)
}
dev.off()
dissimColors <- gray.colors(30, start = 0.9, end = 0.1, gamma = 2.2, alpha = NULL)
ages <- as.numeric(rownames(scpdSM))
ageColors <- rainbow(length(ages), start=0, end=4/6)
heatmap(scpdSM, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors, tracecol=NA)
constrained <- chclust(scpdSM_bray, method="coniss")
bstick <- bstick(constrained, 10)
ngroups <- min(which(bstick$dispersion>bstick$bstick))
x <- strat.plot(scpdSM, yvar=ages, title="", y.rev=T, cex.xlabel=0.5,cex.yaxis=0.5, cex.axis=0.5, clust=constrained)
addClustZone(x, constrained, col="red", ngroups)
consDendro <- as.dendrogram(constrained)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA, dendrogram="row")
fit1 <- adjClust(scpdSM_bray, type="dissimilarity")
plot(fit1, leaflab="perpendicular")
constrained <- chclust(scpdSM_bray, method="coniss")
bstick <- bstick(constrained, 10)
?bstick
data(varespec)
vare.pca <- rda(varespec, scale = TRUE)
bstick(vare.pca)
bstick(vare.pca)
screeplot(vare.pca, bstick = TRUE, type = "lines")
library('vegan')
library('cluster')
library('rioja')
library('gplots')
library('adjclust')
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
pollen12K <- read.csv(file="data/12000.interp.data_clean_sites.csv")
scpdSM_euc <- vegdist(scpdSM, method="euclidean")
scpdSM_bray <- vegdist(scpdSM, method="bray")
scpdSM_chao <- vegdist(scpdSM, method="chao")
print(scpdSM_euc)
print(scpdSM_euc)
min(scpdSM_bray)
min(scpdSM_euc)
?hclust
?hclust
clust_euc_ward.D2 <- hclust(scpdSM_euc, method="ward.D2")
clust_euc_neighbor <- hclust(scpdSM_euc, method="single")
clust_euc_upgma <- hclust(scpdSM_euc, method="average") #UPGMA
clust_euc_wpgma <- hclust(scpdSM_euc, method="mcquitty") #WPGMA
clust_bray_ward.D2 <- hclust(scpdSM_bray, method="ward.D2")
clust_bray_neighbor <- hclust(scpdSM_bray, method="single")
clust_bray_upgma <- hclust(scpdSM_bray, method="average") #UPGMA
clust_bray_wpgma <- hclust(scpdSM_bray, method="mcquitty") #WPGMA
clust_chao_ward.D2 <- hclust(scpdSM_chao, method="ward.D2")
clust_chao_neighbor <- hclust(scpdSM_chao, method="single")
clust_chao_upgma <- hclust(scpdSM_chao, method="average") #UPGMA
clust_chao_wpgma <- hclust(scpdSM_chao, method="mcquitty") #WPGMA
plotting_objs <- ls()[grep("clust", ls())]
print(plotting_objs)
par(mfcol=c(4,3), mar=c(2,4,1,1)+.01)
for (i in 1:length(plotting_objs)){
plot(get(plotting_objs[i]), cex=0.75, xlab=NA, sub=NA, main=plotting_objs[i], hang=-.1)
}
pdf(file="output/cluster_diagrams.pdf", height=11, width=8.5)
par(mfcol=c(4,3), mar=c(2,4,1,1)+.01)
for (i in 1:length(plotting_objs)){
plot(get(plotting_objs[i]), cex=0.75, xlab=NA, sub=NA, main=plotting_objs[i], hang=-.1)
}
dev.off()
dissimColors <- gray.colors(30, start = 0.9, end = 0.1, gamma = 2.2, alpha = NULL)
ages <- as.numeric(rownames(scpdSM))
ageColors <- rainbow(length(ages), start=0, end=4/6)
heatmap(scpdSM, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors, tracecol=NA)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors, tracecol=NA)
constrained <- chclust(scpdSM_bray, method="coniss")
bstick <- bstick(constrained, 10)
ngroups <- min(which(bstick$dispersion>bstick$bstick))  # in this case, no clusters should be retained because even with two groups, the broken stick values are higher than the observed Sum of Squares.
x <- strat.plot(scpdSM, yvar=ages, title="", y.rev=T, cex.xlabel=0.5,cex.yaxis=0.5, cex.axis=0.5, clust=constrained)
x <- strat.plot(scpdSM, yvar=ages, title="", y.rev=T, cex.xlabel=0.5,cex.yaxis=0.5, cex.axis=0.5, clust=constrained)
addClustZone(x, constrained, col="red", ngroups)
consDendro <- as.dendrogram(constrained)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA, dendrogram="row")
#uncomment the following line if you haven't installed these packages yet
#install.packages(c('vegan', 'cluster', 'rioja', 'gplots', 'adjclust))
library('vegan')
library('cluster')
library('rioja')
library('gplots')
library('adjclust')
# also uses stats package, included with base R.
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
pollen12K <- read.csv(file="data/12000.interp.data_clean_sites.csv")
load(file="data/scpdFauna_cleaned.RData") #object is scpdSM
pollen12K <- read.csv(file="data/12000.interp.data_clean_sites.csv")
scpdSM_euc <- vegdist(scpdSM, method="euclidean")
scpdSM_bray <- vegdist(scpdSM, method="bray")
scpdSM_chao <- vegdist(scpdSM, method="chao")
# print(scpdSM_euc)
# print(scpdSM_bray)
# print(scpdSM_chao)
?hclust
clust_euc_ward.D2 <- hclust(scpdSM_euc, method="ward.D2")
clust_euc_neighbor <- hclust(scpdSM_euc, method="single")
clust_euc_upgma <- hclust(scpdSM_euc, method="average") #UPGMA
clust_euc_wpgma <- hclust(scpdSM_euc, method="mcquitty") #WPGMA
clust_bray_ward.D2 <- hclust(scpdSM_bray, method="ward.D2")
clust_bray_neighbor <- hclust(scpdSM_bray, method="single")
clust_bray_upgma <- hclust(scpdSM_bray, method="average") #UPGMA
clust_bray_wpgma <- hclust(scpdSM_bray, method="mcquitty") #WPGMA
clust_chao_ward.D2 <- hclust(scpdSM_chao, method="ward.D2")
clust_chao_neighbor <- hclust(scpdSM_chao, method="single")
clust_chao_upgma <- hclust(scpdSM_chao, method="average") #UPGMA
clust_chao_wpgma <- hclust(scpdSM_chao, method="mcquitty") #WPGMA
plotting_objs <- ls()[grep("clust", ls())]
print(plotting_objs)
# Note: I'm writing the cluster diagram to a pdf file, so it's easier to read. You can uncomment the pdf() and dev.off() lines to print to the screen, or just not copy those lines
pdf(file="output/cluster_diagrams.pdf", height=11, width=8.5)
par(mfcol=c(4,3), mar=c(2,4,1,1)+.01)
for (i in 1:length(plotting_objs)){
plot(get(plotting_objs[i]), cex=0.75, xlab=NA, sub=NA, main=plotting_objs[i], hang=-.1)
}
dev.off()
dissimColors <- gray.colors(30, start = 0.9, end = 0.1, gamma = 2.2, alpha = NULL)
ages <- as.numeric(rownames(scpdSM))
ageColors <- rainbow(length(ages), start=0, end=4/6)
heatmap(scpdSM, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors)
heatmap.2(scpdSM, dendrogram='row', col=dissimColors, distfun=function(m) vegdist(m,method="bray"), hclustfun=function(m) hclust(m, method="average"), RowSideColors = ageColors, tracecol=NA)
constrained <- chclust(scpdSM_bray, method="coniss")
bstick <- bstick(constrained, 10)
ngroups <- min(which(bstick$dispersion>bstick$bstick))  # in this case, no clusters should be retained because even with two groups, the broken stick values are higher than the observed Sum of Squares.
x <- strat.plot(scpdSM, yvar=ages, title="", y.rev=T, cex.xlabel=0.5,cex.yaxis=0.5, cex.axis=0.5, clust=constrained)
addClustZone(x, constrained, col="red", ngroups)
consDendro <- as.dendrogram(constrained)
heatmap.2(scpdSM, Rowv= consDendro, col=dissimColors, distfun=function(m) vegdist(m,method="bray"), RowSideColors = ageColors, tracecol=NA, dendrogram="row")
fit1 <- adjClust(scpdSM_bray, type="dissimilarity")
plot(fit1, leaflab="perpendicular")
